package com.xuzz.study.io.nio;

import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class NioFileChannel {
    public static void main(String[] args) throws Exception  {
        String str = "New String to write to file...";
        FileOutputStream fileOutputStream = new FileOutputStream("G:\\study\\JavaStudy\\file01.txt");
        FileChannel channel = fileOutputStream.getChannel();
        ByteBuffer allocate = ByteBuffer.allocate(1024);
        allocate.put(str.getBytes());
        allocate.flip();
        while(allocate.hasRemaining())
        {
            channel.write(allocate);
        }
        fileOutputStream.close();
        channel.close();
    }
}
